<div class="tabs ui-tabs ui-widget ui-widget-content ui-corner-all">
  <ul class="tab-menu ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
    <li class="ui-state-default ui-corner-top <?php echo $tag == 'detail' ? 'ui-tabs-selected ui-state-active' : '' ?>">
      <a href="#promotion-details-tab">
        <span><?php echo $this->lang->line('label.' . $this->router->fetch_class() . '.detail') ?></span>
      </a>
    </li>
    <li class="ui-state-default ui-corner-top <?php echo $tag == 'media' ? 'ui-tabs-selected ui-state-active' : '' ?>">
      <a href="#promotion-media-tab">
        <span><?php echo $this->lang->line('label.' . $this->router->fetch_class() . '.media') ?></span>
      </a>
    </li>
    <li class="ui-state-default ui-corner-top <?php echo $tag == 'relate' ? 'ui-tabs-selected ui-state-active' : '' ?>">
      <a href="#promotion-relate-tab">
        <span><?php echo $this->lang->line('label.' . $this->router->fetch_class() . '.relate') ?></span>
      </a>
    </li>
    <li class="ui-state-default ui-corner-top <?php echo $tag == 'statistics' ? 'ui-tabs-selected ui-state-active' : '' ?>">
      <a href="#promotion-statistics-tab">
        <span><?php echo $this->lang->line('label.statistics') ?></span>
      </a>
    </li>
  </ul>
  <!-- Content tab -->
  <div id="promotion-details-tab" class="form_inputs ui-tabs-panel ui-widget-content ui-corner-bottom">
    <fieldset>
      <ul>
        <li>
          <label for="title"><?php echo $this->lang->line('label.promotion.title') ?></label>
          <div class="input"><?php echo $obj["title"] ?>
          </div>
        </li>
        <li>
          <label for="description"><?php echo $this->lang->line('label.promotion.description') ?></label>
          <div class="input"><?php echo $obj["description"] ?>
          </div>
        </li>
        <li>
          <label for="provider_user_id"><?php echo $this->lang->line('label.promotion.provider_user_id') ?></label>
          <div class="input">
            <?php
            $ref_obj = $this->provider_user_model->get($obj["provider_user_id"]);
            if ($ref_obj) {
              ?>
              <a href="<?php echo site_url('admin/'."provider_user/show/" . $obj["provider_user_id"]) ?>">
                <?php echo $this->provider_user_model->to_string($ref_obj) ?></a>
            <?php } ?>
          </div>
        </li>
        <li>
          <label for="start_date"><?php echo $this->lang->line('label.promotion.start_date') ?></label>
          <div class="input">
            <?php echo !empty($obj["start_date"]) ? date($this->setting_model->item('date_format'), $obj["start_date"]) : '' ?>
          </div>
        </li>
        <li>
          <label for="end_date"><?php echo $this->lang->line('label.promotion.end_date') ?></label>
          <div class="input">
            <?php echo !empty($obj["end_date"]) ? date($this->setting_model->item('date_format'), $obj["end_date"]) : '' ?>
          </div>
        </li>
        <li>
          <label for="status"><?php echo $this->lang->line('label.promotion.status') ?></label>
          <div class="input">
            <?php
            $status = array(
                PROMOTION_NEW => $this->lang->line('label.promotion.status.new'),
                PROMOTION_PEDDING => $this->lang->line('label.promotion.status.pedding'),
                PROMOTION_APPROVED => $this->lang->line('label.promotion.status.approve'),
                PROMOTION_PUBLISH => $this->lang->line('label.promotion.status.publish'),
                PROMOTION_REJECT => $this->lang->line('label.promotion.status.reject'),
                PROMOTION_BLOCK => $this->lang->line('label.promotion.status.block'));
            ?>
            <strong><?php echo empty($status[$obj['status']]) ? '' : $status[$obj['status']] ?></strong>
          </div>
        </li>
        <li>
          <label for="map"><?php echo $this->lang->line('label.promotion.location') ?></label>
          <div class="input">
            <script src="//maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=<?php echo $this->setting_model->item('googlemap_api') ?>"
            type="text/javascript"></script>
            <script type="text/javascript">
              var map, marker;
              var default_lat = <?php echo isset($obj['lat']) ? $obj['lat'] : '37.4419' ?>;
              var default_lng = <?php echo isset($obj['lng']) ? $obj['lng'] : '-122.1419' ?>;
  
              function create_marker(point){
                marker = new GMarker(point, {draggable: false});    
                map.addOverlay(marker);
              }
              function initialize() {
                if (GBrowserIsCompatible()) {
                  map = new GMap2(document.getElementById("map"));
                  map.addControl(new GMapTypeControl());
                  map.addControl(new GScaleControl());
                  map.enableScrollWheelZoom();
                  var customUI = map.getDefaultUI();
                  customUI.maptypes.hybrid = false;
                  map.setUI(customUI);
                  var center = new GLatLng( default_lat, default_lng );
                  map.setCenter(center, 13);
                  create_marker(center);
                }
              }
              jQuery(document).ready(function(){
                initialize();       
              });  
            </script>
            <div id="map" style="width: 460px;height:200px;"></div>
          </div>
        </li>
        <li>
          <label for="rate_point"><?php echo $this->lang->line('label.promotion.rate_point') ?></label>
          <div class="input"><?php echo $obj["rate_point"] ?>
          </div>
        </li>
        <li>
          <label for="country_id">
            <?php echo $this->lang->line('label.promotion.country_id') ?> / 
            <?php echo $this->lang->line('label.promotion.city_id') ?>
          </label>
          <div class="input">
            <?php
            $ref_obj = $this->country_model->get($obj["country_id"]);
            if ($ref_obj) {
              ?>
              <a href="<?php echo site_url('admin/'."country/show/" . $obj["country_id"]) ?>">
                <?php echo $this->country_model->to_string($ref_obj) ?></a>
            <?php } ?> / 
            <?php
            $ref_obj = $this->city_model->get($obj["city_id"]);
            if ($ref_obj) {
              ?>
              <a href="<?php echo site_url('admin/'."city/show/" . $obj["city_id"]) ?>">
                <?php echo $this->city_model->to_string($ref_obj) ?></a>
            <?php } ?>
          </div>
        </li>
        <li>
          <label for="is_hot"><?php echo $this->lang->line('label.promotion.is_hot') ?></label>
          <div class="input"><?php echo empty($obj["is_hot"]) ? $this->lang->line("label.no") : $this->lang->line("label.yes") ?></div>
        </li>
        <li>
          <label for="date_create"><?php echo $this->lang->line('label.promotion.date_create') ?></label>
          <div class="input">
            <?php echo !empty($obj["date_create"]) ? date($this->setting_model->item('date_format'), $obj["date_create"]) : '' ?>
          </div>
        </li>
        <li>
          <label for="date_update"><?php echo $this->lang->line('label.promotion.date_update') ?></label>
          <div class="input">
            <?php echo !empty($obj["date_update"]) ? date($this->setting_model->item('date_format'), $obj["date_update"]) : '' ?>
          </div>
        </li>
        <li>
          <label for="date_publish"><?php echo $this->lang->line('label.promotion.date_publish') ?></label>
          <div class="input">
            <?php echo !empty($obj["date_publish"]) ? date($this->setting_model->item('date_format'), $obj["date_publish"]) : '' ?>
          </div>
        </li>
        <li>
          <label for="max_per_person"><?php echo $this->lang->line('label.promotion.max_per_person') ?></label>
          <div class="input"><?php echo $obj["max_per_person"] ?>
          </div>
        </li>
        <li>
          <label for="max_download"><?php echo $this->lang->line('label.promotion.max_download') ?></label>
          <div class="input"><?php echo $obj["max_download"] ?>
          </div>
        </li>
        <li>
          <label for="remain"><?php echo $this->lang->line('label.promotion.remain') ?></label>
          <div class="input"><?php echo $obj["remain"] ?>
          </div>
        </li>        
        <li>
          <label for="support_channel"><?php echo $this->lang->line('label.promotion.support_channel') ?></label>
          <div class="input">
            <?php
            $support_channel = array(
                PROMOTION_CHANNEL_ALL => $this->lang->line('label.promotion.support_channel.all'),
                PROMOTION_CHANNEL_EMAIL => $this->lang->line('label.promotion.support_channel.email'),
                PROMOTION_CHANNEL_SMS => $this->lang->line('label.promotion.support_channel.sms'));
            ?>
            <?php echo empty($support_channel[$obj["support_channel"]]) ? '' : $support_channel[$obj["support_channel"]] ?>
          </div>
        </li>
        <li>
          <label for="support_encode"><?php echo $this->lang->line('label.promotion.support_encode') ?></label>
          <div class="input">
            <?php
            $support_encode = array(
                PROMOTION_ENCODE_ALL => $this->lang->line('label.promotion.support_encode.all'),
                PROMOTION_ENCODE_BARCODE => $this->lang->line('label.promotion.support_encode.barcode'),
                PROMOTION_ENCODE_TEXT => $this->lang->line('label.promotion.support_encode.text'));
            ?>
            <?php echo empty($support_encode[$obj["support_encode"]]) ? '' : $support_encode[$obj["support_encode"]] ?>
          </div>
        </li>
        <li>
          <label for="code"><?php echo $this->lang->line('label.promotion.code') ?></label>
          <div class="input"><?php echo $obj["code"] ?>
          </div>
        </li>
        <li>
          <label for="is_active"><?php echo $this->lang->line('label.promotion.is_active') ?></label>
          <div class="input"><?php echo empty($obj["is_active"]) ? $this->lang->line("label.no") : $this->lang->line("label.yes") ?></div>
        </li>
      </ul>
    </fieldset>
    <div class="buttons float-right padding-top">      
      <a class="btn blue edit" href="<?php echo site_url('admin/'.$this->router->fetch_class() . '/edit/' . $obj['id']) ?>">
        <?php echo $this->lang->line('btn.edit') ?>
      </a>
      <?php if ($obj['status'] != PROMOTION_APPROVED) { ?>
        <a class="btn orange edit confirm" href="<?php echo site_url('admin/promotion/approve/' . $obj['id']) ?>">
          <?php echo $this->lang->line('btn.approve') ?>
        </a>
      <?php } ?>
      <?php if ($obj['status'] != PROMOTION_PUBLISH) { ?>
        <a class="btn blue edit confirm" href="<?php echo site_url('admin/promotion/publish/' . $obj['id']) ?>">
          <?php echo $this->lang->line('btn.publish') ?>
        </a>
      <?php } ?>
      <?php if ($obj['status'] != PROMOTION_REJECT) { ?>
        <a class="btn green edit  confirm" href="<?php echo site_url('admin/promotion/reject/' . $obj['id']) ?>">
          <?php echo $this->lang->line('btn.reject') ?>
        </a>  
      <?php } ?>
      <?php if ($obj['status'] != PROMOTION_BLOCK) { ?>
        <a class="btn orange edit  confirm" href="<?php echo site_url('admin/promotion/block/' . $obj['id']) ?>">
          <?php echo $this->lang->line('btn.block') ?>
        </a>
      <?php } ?>
      <a class="btn gray cancel" href="<?php echo site_url('admin/'.$this->router->fetch_class()) ?>">
        <?php echo $this->lang->line('btn.cancel') ?>
      </a>
      <a class="confirm btn red delete" href="<?php echo site_url('admin/'.$this->router->fetch_class() . '/delete/' . $obj['id']) ?>">
        <?php echo $this->lang->line('btn.delete') ?>
      </a>
    </div>
  </div>
  <div id="promotion-media-tab" class="form_inputs ui-tabs-panel ui-widget-content ui-corner-bottom">
    <fieldset>
      <?php foreach ($media_promotions as $media) { ?>
        <section class="title" style="width:200px;margin: 10px;float:left">
          <a href="<?php echo site_url('admin/promotion_media/delete/' . $media['id'] . '/' . $media['promotion_id']) ?>"
             class="confirm delete" >
            <img title="<?php echo $this->lang->line('label.promotion.delete') ?>"
                 style="float:right;" src="<?php echo base_url() . APPPATH . 'themes/admin/img/icons/delete.png' ?>">
          </a>
          <a class="folder-hash preview modal cboxElement tooltip-s" title="<?php echo $media['original_name'] ?>" 
             href="<?php echo site_url('admin/promotion_media/show/' . $media['id']) ?>">
            <img width="200px" height="200px" src="<?php echo site_url('admin/promotion_media/preview/' . $media['id']) ?>" alt=""/>
          </a>          
        </section>
      <?php } ?>
    </fieldset>
    <div class="buttons float-right padding-top">
      <a class="btn green add" href="<?php echo site_url('admin/promotion_media/create/' . $obj['id']) ?>">
        <?php echo $this->lang->line('btn.add.media') ?>
      </a>      
    </div>
  </div>
  <div id="promotion-relate-tab" class="form_inputs ui-tabs-panel ui-widget-content ui-corner-bottom">
    <fieldset>
      <ul>
        <table border="0" class="table-list">
          <thead>
            <tr>
              <th><?php echo $this->lang->line("label.promotion_relate.promotion2_id") ?></th>
              <th></th>
            </tr>
          </thead>
          <tbody>
            <?php
            $temp = array();
            foreach ($relate_promotions as $relate) {
              $obj_id = $relate["promotion2_id"] != $obj['id'] ? $relate["promotion2_id"] : $relate["promotion1_id"];
              if (!in_array($obj_id, $temp)) {
                $temp[] = $obj_id;
                ?>
                <tr>
                  <td>
                    <?php
                    $ref_obj = $this->promotion_model->get($obj_id);
                    if ($ref_obj) {
                      ?>
                      <a href="<?php echo site_url('admin/'."promotion/show/" . $ref_obj["id"]) ?>">
                        <?php echo $this->promotion_model->to_string($ref_obj) ?></a>
                    <?php } ?>
                  </td>
                  <td>
                    <img width="120px" src="<?php echo site_url('admin/promotion_media/preview_promotion/' . $obj_id) ?>" alt="">
                  </td>
                </tr>
              <?php }
            } ?>
          </tbody>
        </table>
      </ul>
    </fieldset>
    <div class="buttons float-right padding-top">
      <a class="btn green add" href="<?php echo site_url('admin/promotion_relate/create/' . $obj['id']) ?>">
        <?php echo $this->lang->line('btn.add.relate') ?>
      </a>      
    </div>
  </div>
  <div id="promotion-statistics-tab" class="form_inputs ui-tabs-panel ui-widget-content ui-corner-bottom">
    <fieldset>
      <ul>
        <li>
          <label for="title"><?php echo $this->lang->line('label.promotion.view') ?></label>
          <div class="input">
            <a href="<?php echo site_url('admin/promotion_view/search?promotion_id='.$obj['id'])?>">
              <?php echo $obj['views'] ?>
            </a>
          </div>
        </li>
        <li>
          <label for="title"><?php echo $this->lang->line('label.promotion.download') ?></label>
          <div class="input">
            <a href="<?php echo site_url('admin/promotion_download/search?promotion_id='.$obj['id'])?>">
              <?php echo $obj['downloads'] ?>
            </a>
          </div>
        </li>
        <li>
          <label for="title"><?php echo $this->lang->line('label.promotion.rating') ?></label>
          <div class="input">
            <a href="<?php echo site_url('admin/promotion_rating/search?promotion_id='.$obj['id'])?>">
              <?php echo $obj['rating'] ?>
            </a>
          </div>
        </li>
      </ul>
    </fieldset>
  </div>
</div>